home *** CD-ROM | disk | FTP | other *** search
- /*
- * SHOW.C -- Show data
- *
- * Copyright (C) 1991 by Jarkko Vuori. All rights reserved.
- * Author(s): J Vuori
- * Modification(s):
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <conio.h>
- #include <ctype.h>
- #include "dspldrv.h"
-
- #define DX 512 // number of horisontal lines
- #define DY 256 // vertical lines
-
- #define STEP 16
-
-
- static struct {
- unsigned ctrlC:1;
- unsigned reso:1;
- } flags;
- int data[512];
-
- /*
- * CTRL-C handler
- */
- void cdecl CtrlCHandler(void) {
- flags.ctrlC = 1;
- }
-
-
- static int nextl(FILE *fd, long *data) {
- int c;
- char buff[80], *p;
-
- /* first flush leading space out */
- p = buff;
- while (c = getc(fd), !isdigit(c) && c != '-' && c != EOF);
- *p++ = c;
- if (c == EOF) return (EOF);
-
- /* then get the main body of the character */
- while (c = getc(fd), c != EOF && (isdigit(c) || c == '-'))
- *p++ = c;
-
- *p = '\0';
-
- *data = atol(buff) > 8388608L ? atol(buff)-16777216 : atol(buff);
-
- return (0);
- }
-
-
- int cdecl main(int argc, char *argv[]) {
- FILE *fd = NULL;
- long d, max = -2147483647, min = 2147483646;
- int i, j, c, val;
-
- //signal(SIGINT, CtrlCHandler);
-
- if (!(fd = fopen(argc < 2 ? "LOG.DAT" : *++argv, "r"))) {
- fprintf(stderr, "can't open file '%s'\n", argc < 2 ? "LOG.DAT" : *argv);
- return (1);
- }
- setvbuf(fd, NULL, _IOFBF, 8192);
-
- if (InitDspl(DX, DY)) {
- fprintf(stderr, "%s: no support for needed graphics device\n", __FILE__);
- return (1);
- }
-
- /* serach max and min values */
- while (nextl(fd, &d) != EOF) {
- max = max(max, d);
- min = min(min, d);
- }
- rewind(fd);
-
- c = ' '; j = 512;
- do {
- ErasePlot();
-
- if (c == 't') {
- j = 0;
- flags.reso = !flags.reso;
- }
-
- /* read a new block if needed */
- if (j == 512) {
- for (i = 0; i < 512; i++)
- if (nextl(fd, &d) == EOF)
- data[i] = 0;
- else
- data[i] = (int)(255.0*(d-min)/(max-min)+.5);
- j = 0;
- }
-
- for (i = 0; i < 512; i++) {
- if (flags.reso ? !(i % STEP) : 1) {
- val = data[j++];
- if (flags.reso) PlotCircle(i, val);
- }
-
- PlotLine(i, val);
- }
-
- if (max > 0 && min < 0)
- PlotZeroLine(-min*256L/(max-min));
-
- while(!kbhit());
- } while ((c = getch()) != '.');
-
- end:
- ReleaseDspl();
- return (0);
- }
-